package com.gzyj.server.factory.jtt808.up;

import com.gzyj.data.common.VehicleIncrement;
import com.gzyj.jtt808.v2013.HeaderMsgBodyProperty;
import com.gzyj.jtt808.v2013.Package;
import com.gzyj.jtt808.v2013.enums.JT808TerminalResult;
import com.gzyj.jtt808.v2013.protocol.JTT808_0x0001;
import com.gzyj.jtt808.v2013.protocol.JTT808_0x8001;
import com.gzyj.server.factory.CommonHandler;
import com.gzyj.server.factory.jtt808.NetWorkSerrvice;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.security.spec.MGF1ParameterSpec;

/**
 * @author lhj
 */
@Component
public class JTT808_0x0001_Handler implements CommonHandler {

    @Autowired
    private NetWorkSerrvice netWorkSerrvice;

    @Override
    public void handler(ChannelHandlerContext ctx, Package msg) throws Exception {
        JTT808_0x0001 jtt8080x0001=(JTT808_0x0001)msg;

        JTT808_0x8001 jtt808_0x8001 = new JTT808_0x8001();

        HeaderMsgBodyProperty headerMsgBodyProperty = new HeaderMsgBodyProperty();
        headerMsgBodyProperty.setSubcontract(jtt8080x0001.getPackageHeader().getMsgBodyProperty().isSubcontract());
        headerMsgBodyProperty.setEncryptMethod(jtt8080x0001.getPackageHeader().getMsgBodyProperty().getEncryptMethod());
        jtt808_0x8001.getPackageHeader().setMsgBodyProperty(headerMsgBodyProperty);
        jtt808_0x8001.getPackageHeader().setTerminalPhoneNo(jtt8080x0001.getPackageHeader().getTerminalPhoneNo());

        jtt808_0x8001.setMsgNum(jtt8080x0001.getPackageHeader().getMsgNum());
        jtt808_0x8001.setAckMsgId(jtt8080x0001.getPackageHeader().getMsgId());
        jtt808_0x8001.setResult(JT808TerminalResult.成功_确认);
        netWorkSerrvice.send2Veh(jtt8080x0001.getPackageHeader().getTerminalPhoneNo(), jtt808_0x8001.encode());
    }


    @Override
    public void handler(ChannelHandlerContext ctx, com.gzyj.jtt808.v2019.Package msg) throws Exception {

    }

    @Override
    public void handler(ChannelHandlerContext ctx, com.gzyj.jtt808.v2011.Package msg) {

    }

    @Override
    public void handler(VehicleIncrement vehicleInfo, String msg) {

    }
}
